﻿namespace MyCoreLib.Automation.Data.SqlClient.Model
{
    using System;
    using System.Collections.ObjectModel;
    using System.Linq;

    public class ContractInfo
    {
        public readonly string Name;

        public readonly string Description;

        public readonly ReadOnlyCollection<ContractFieldInfo> Fields;

        public ContractInfo(IOutput output, IContract contract)
        {
            if (ReferenceEquals(contract, null))
            {
                throw new ArgumentNullException("contract");
            }

            if (string.IsNullOrWhiteSpace(contract.Name))
            {
                throw new NotImplementedException();
            }

            if (ReferenceEquals(contract.Fields, null))
            {
                throw new NotImplementedException();
            }

            Name = contract.Name.Trim();
            Description = string.IsNullOrWhiteSpace(contract.Description)
                ? this.Name
                : contract.Description.Trim();
            Fields =
                new ReadOnlyCollection<ContractFieldInfo>(
                    contract.Fields.Select(f => new ContractFieldInfo(output, f)).ToList());

        }
    }
}
